<?php
require('../include/init.inc.php');
$method = $app_key = $merchant_id = $tran_no = $api_url1 = $api_url2 = $website = $note = '';
extract($_REQUEST, EXTR_IF_EXISTS);

if (Common::isPost()) {
    //先检查没有配置就是插入
    isset($api_url1) ? $api_url1 : "";
    isset($api_url2) ? $api_url2 : "";

    $websiteName = AdminDbConfig::getSiteNameBySite($website);
    $update_data = array("app_site" => $website, "app_name" => $websiteName['website_name'], "merchant_id" => $merchant_id, "tran_num" => $tran_no, "app_key" => $app_key, "note" => $note, "api_url1" => $api_url1, "api_url2" => $api_url2, "createtime" => time());
    $ret = AdminPayConfig::getInfo($website);


    if ($ret) {
        $result = AdminPayConfig::update($ret['id'], $update_data);
    } else {
        $result = AdminPayConfig::add($update_data);
    }


    if ($result) {
        SysLog::addLog(UserSession::getUserName(), 'MODIFY', 'Pay', $title, json_encode($update_data));
        Common::exitWithSuccess('更新完成', 'pay_manage/pay.php');
    } else {
        OSAdmin::alert("error");
    }
}

$websiteOptions = AdminDbConfig::getSiteForOptions();
Template::assign('websiteOptions', $websiteOptions);
Template::display('pay_manage/pay.tpl');